package com.ysd.dao.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.ysd.entity.HomeInfo;
import com.ysd.util.DBManage;
public class HomeInfoDao {
	public HomeInfo getAllIndex(){
		HomeInfo h=null;
		
		try {
			Connection conn = DBManage.getConn();
			Statement stam = conn.createStatement();
			String sql="select id,homeInfo,info,culture,zsTel,lxTel,email,address,x,y FROM HomeInfo";
			ResultSet rs=stam.executeQuery(sql);
			while(rs.next()) {
				 int id = rs.getInt("id");
				 String homeInfo = rs.getString("homeInfo") ;
				 String info = rs.getString("info");
				 String culture = rs.getString("culture");
				 String zsTel = rs.getString("zsTel");
				 String lxTel = rs.getString("lxTel");
				 String email = rs.getString("email");
				 String address = rs.getString("address");
				 double x=rs.getDouble("x");
				 double y=rs.getDouble("y");
			
					h=new HomeInfo(id,homeInfo,info,culture,zsTel,lxTel,email,address,x,y);
				}
			DBManage.colseAll(rs, stam, conn);	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			return h;
	} 
	public int update(String homeInfo,String info,String culture,String zsTel,String lxTel,String email,String address,double x,double y) {
		int i=0;
		
		try {
			Connection conn = DBManage.getConn();
			Statement stam = conn.createStatement();
			String sql="UPDATE homeinfo SET homeInfo='"+homeInfo+"', info='"+info+"', culture='"+culture+"', zsTel='"+zsTel+"', lxTel='"+lxTel+"', email='"+email+"', address='"+address+"',x='"+x+"',y='"+y+"'";
			i=stam.executeUpdate(sql);
			DBManage.colseAll(null, stam, conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
		
	}
}
